from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

try:
    # 尝试直接用 Transformers 加载
    model = AutoModelForCausalLM.from_pretrained(
        "/mnt/codes/qwen3/fine-tuning/Qwen3-8B-finetuned-fp16",
        torch_dtype=torch.float16,
        device_map="auto",
        trust_remote_code=True
    )
    print("✅ 模型可以被 Transformers 正确加载")
    
    # 测试简单推理
    tokenizer = AutoTokenizer.from_pretrained(
        "/mnt/codes/qwen3/fine-tuning/Qwen3-8B-finetuned-fp16"
    )
    
    inputs = tokenizer("Hello", return_tensors="pt").to(model.device)
    with torch.no_grad():
        outputs = model.generate(**inputs, max_new_tokens=10)
    print("✅ 模型推理测试通过")
    
except Exception as e:
    print(f"❌ 模型加载失败: {e}")
    import traceback
    traceback.print_exc()